﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace AcessoDados
{
    public class TipoProdutoDAO : IDisposable
    {
        SqlConnection conexao = null;
        public void Save(Negocio.TipoProduto tipo)
        {
            conexao = new ConnectionFactory().criaConexao();
            using (conexao)
            {
                SqlCommand command = new SqlCommand();
                command = conexao.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                string query = @"";
                command.CommandText = query;
                command.ExecuteNonQuery();
            }
        }

        public void Update(Negocio.TipoProduto tipo)
        {
            conexao = new ConnectionFactory().criaConexao();
            using (conexao)
            {
                SqlCommand command = new SqlCommand();
                command = conexao.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                string query = @"";
                command.CommandText = query;
                command.ExecuteNonQuery();
            }
        }

        public void Delete(int id)
        {
            conexao = new ConnectionFactory().criaConexao();
            using (conexao)
            {
                SqlCommand command = new SqlCommand();
                command = conexao.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                string query = @"";
                command.CommandText = query;
                command.ExecuteNonQuery();
            }
        }

        public List<Negocio.TipoProduto> Select()
        {
            conexao = new ConnectionFactory().criaConexao();
            List<Negocio.TipoProduto> tipPro = new List<Negocio.TipoProduto>();
            using (conexao)
            {
                SqlCommand command = new SqlCommand();
                command = conexao.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                string query = @"SELECT * FROM TIPPRO";
                command.CommandText = query;
                SqlDataAdapter sdAdapter = new SqlDataAdapter(command);
                DataTable dt = new DataTable();
                sdAdapter.Fill(dt);
                
                foreach (DataRow dr in dt.Rows)
                {
                    Negocio.TipoProduto item = new Negocio.TipoProduto();
                    item.TppID = Convert.ToInt32(dr["TppID"]);
                    item.TppDes = Convert.ToString(dr["TppDes"]);
                    tipPro.Add(item);
                }
            }
            return tipPro;
        }

        public void Dispose()
        {
            if (conexao != null)
            {
                conexao.Close();
                conexao.Dispose();
                

            }
        }

    }
}
